package com.supor.aiot.common.helper;

import android.app.Activity;

import java.util.Stack;

public class ConfigActivityManager {
    private static Stack<Activity> mConfigActivityStack = new Stack<Activity>();
    /**
     * 前台Activity
     */
    public static Activity ForegroundActivity;

    public static void addActivity(Activity activity) {
        mConfigActivityStack.push(activity);
    }

    public static void removeActivity(Activity activity) {
        mConfigActivityStack.remove(activity);
    }

    public static void removeActivity() {
        mConfigActivityStack.pop();
    }

    public static Activity getActivity(int index) {
        return mConfigActivityStack.get(index);
    }

    public static int getActivityCount() {
        return mConfigActivityStack.size();
    }

    public static void finishAll() {
        for (Activity activity : mConfigActivityStack) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
        mConfigActivityStack.clear();
    }

    public static Activity hasActivity(String clzName) {
        if (mConfigActivityStack.size() == 0) {
            return null;
        }
        for (Activity activity : mConfigActivityStack) {
            if (clzName.equalsIgnoreCase(activity.getClass().getSimpleName())) {
                return activity;
            }
        }
        return null;
    }

    public static Stack<Activity> getAllActivity() {
        return mConfigActivityStack;
    }

}

